package com.powernode.ex.handler;

import com.powernode.constant.BussinessEnum;
import com.powernode.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.nio.file.AccessDeniedException;

/**
 * ClassName:GlobalExceptionHandle
 * Package:com.powernode.ex.handler
 * Description:
 * 全局异常处理类
 * @date:2025/1/25 16:15
 * @author:bailihua
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandle {

    @ExceptionHandler(BusinessException.class)
    public Result<String> businessException(BusinessException e){
        log.error(e.getMessage());
        return Result.fail(BussinessEnum.OPERATION_FAIL.getCode(),e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public Result<String> runtimeException(RuntimeException e){
        log.error(e.getMessage());
        return Result.fail(BussinessEnum.SERVER_INNER_ERRPR);
    }

    @ExceptionHandler(AccessDeniedException.class)
    public Result<String> accessDeniedException(AccessDeniedException e) throws AccessDeniedException {
        log.error(e.getMessage());
        throw e;
    }
}
